package com.bite.product.controller;

import com.bite.product.model.ProductInfo;
import com.bite.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/{productId}")
    public ProductInfo getProductById(@PathVariable("productId") Integer productId) {
        log.info("接受参数 productId: {}", productId);
        return productService.selectProductById(productId);
    }

    @RequestMapping("/basic")
    public String basicType(Integer id, String name) {
        return "product-service [basicType]接口被调用: " + id + " " + name;
    }

    @RequestMapping("/object")
    public String objectType(ProductInfo productInfo) {
        return "product-service [objectType]接口被调用: " + productInfo.toString();
    }

    @RequestMapping("/json")
    public String jsonType(@RequestBody ProductInfo productInfo) {
        return "product-service [jsonType]接口被调用: " + productInfo.toString();
    }

}
